home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 104 / MacAddict_104_2005-04.iso / Software / Internet & Communication / WordPress 1.2.2 freeware.dmg / wordpress / wp-admin / post.php < prev    next >
Encoding:
PHP Script  |  2004-10-13  |  27.1 KB  |  813 lines

  1. <?php
  2. /* <Edit> */
  3.  
  4. require_once('../wp-includes/wp-l10n.php');
  5.  
  6. function add_magic_quotes($array) {
  7. foreach ($array as $k => $v) {
  8.     if (is_array($v)) {
  9.         $array[$k] = add_magic_quotes($v);
  10.     } else {
  11.         $array[$k] = addslashes($v);
  12.     }
  13. }
  14. return $array;
  15. }
  16.  
  17. if (!get_magic_quotes_gpc()) {
  18. $_GET    = add_magic_quotes($_GET);
  19. $_POST   = add_magic_quotes($_POST);
  20. $_COOKIE = add_magic_quotes($_COOKIE);
  21. }
  22.  
  23. $wpvarstoreset = array('action', 'safe_mode', 'withcomments', 'posts', 'poststart', 'postend', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder');
  24.  
  25. for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  26. $wpvar = $wpvarstoreset[$i];
  27. if (!isset($$wpvar)) {
  28.     if (empty($_POST["$wpvar"])) {
  29.         if (empty($_GET["$wpvar"])) {
  30.             $$wpvar = '';
  31.         } else {
  32.             $$wpvar = $_GET["$wpvar"];
  33.         }
  34.     } else {
  35.         $$wpvar = $_POST["$wpvar"];
  36.     }
  37. }
  38. }
  39.  
  40. switch($action) {
  41.  
  42.  
  43. case 'post':
  44.  
  45.         $standalone = 1;
  46.         require_once('admin-header.php');
  47.  
  48.         $post_pingback = intval($_POST['post_pingback']);
  49.         $content = balanceTags($_POST['content']);
  50.         $content = format_to_post($content);
  51.         $excerpt = balanceTags($_POST['excerpt']);
  52.         $excerpt = format_to_post($excerpt);
  53.         $post_title = addslashes($_POST['post_title']);
  54.         $post_categories = $_POST['post_category'];
  55.         if(get_settings('use_geo_positions')) {
  56.             $latstr = $_POST['post_latf'];
  57.             $lonstr = $_POST['post_lonf'];
  58.             if((strlen($latstr) > 2) && (strlen($lonstr) > 2 ) ) {
  59.                 $post_latf = floatval($_POST['post_latf']);
  60.                 $post_lonf = floatval($_POST['post_lonf']);
  61.             }
  62.         }
  63.         $post_status = $_POST['post_status'];
  64.         $post_name = $_POST['post_name'];
  65.  
  66.         if (empty($post_status)) $post_status = 'draft';
  67.         $comment_status = $_POST['comment_status'];
  68.         if (empty($comment_status)) $comment_status = get_settings('default_comment_status');
  69.         $ping_status = $_POST['ping_status'];
  70.         if (empty($ping_status)) $ping_status = get_settings('default_ping_status');
  71.         $post_password = addslashes(stripslashes($_POST['post_password']));
  72.         
  73.         if (empty($post_name))
  74.             $post_name = sanitize_title($post_title);
  75.         else
  76.             $post_name = sanitize_title($post_name);
  77.  
  78.         $trackback = $_POST['trackback_url'];
  79.     // Format trackbacks
  80.     $trackback = preg_replace('|\s+|', '\n', $trackback);
  81.  
  82.     if ($user_level == 0)
  83.         die (__('Cheatin’ uh?'));
  84.  
  85.     if (($user_level > 4) && (!empty($_POST['edit_date']))) {
  86.         $aa = $_POST['aa'];
  87.         $mm = $_POST['mm'];
  88.         $jj = $_POST['jj'];
  89.         $hh = $_POST['hh'];
  90.         $mn = $_POST['mn'];
  91.         $ss = $_POST['ss'];
  92.         $jj = ($jj > 31) ? 31 : $jj;
  93.         $hh = ($hh > 23) ? $hh - 24 : $hh;
  94.         $mn = ($mn > 59) ? $mn - 60 : $mn;
  95.         $ss = ($ss > 59) ? $ss - 60 : $ss;
  96.     $now = "$aa-$mm-$jj $hh:$mn:$ss";
  97.     $now_gmt = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss");
  98.     } else {
  99.     $now = current_time('mysql');
  100.     $now_gmt = current_time('mysql', 1);
  101.     }
  102.  
  103.     // What to do based on which button they pressed
  104.     if ('' != $_POST['saveasdraft']) $post_status = 'draft';
  105.     if ('' != $_POST['saveasprivate']) $post_status = 'private';
  106.     if ('' != $_POST['publish']) $post_status = 'publish';
  107.     if ('' != $_POST['advanced']) $post_status = 'draft';
  108.  
  109.  
  110.     if((get_settings('use_geo_positions')) && (strlen($latstr) > 2) && (strlen($lonstr) > 2) ) {
  111.     $postquery ="INSERT INTO $tableposts
  112.             (ID, post_author, post_date, post_date_gmt, post_content, post_title, post_lat, post_lon, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt)
  113.             VALUES
  114.             ('0', '$user_ID', '$now', '$now_gmt', '$content', '$post_title', $post_latf, $post_lonf,'$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$trackback', '$now', '$now_gmt')
  115.             ";
  116.     } else {
  117.     $postquery ="INSERT INTO $tableposts
  118.             (ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt)
  119.             VALUES
  120.             ('0', '$user_ID', '$now', '$now_gmt', '$content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$trackback', '$now', '$now_gmt')
  121.             ";
  122.     }
  123.     $postquery =
  124.     $result = $wpdb->query($postquery);
  125.  
  126.     $post_ID = $wpdb->get_var("SELECT ID FROM $tableposts ORDER BY ID DESC LIMIT 1");
  127.  
  128.     if (!empty($_POST['mode'])) {
  129.     switch($_POST['mode']) {
  130.         case 'bookmarklet':
  131.             $location = 'bookmarklet.php?a=b';
  132.             break;
  133.         case 'sidebar':
  134.             $location = 'sidebar.php?a=b';
  135.             break;
  136.         default:
  137.             $location = 'post.php';
  138.             break;
  139.         }
  140.     } else {
  141.         $location = 'post.php';
  142.     }
  143.     if ( '' != $_POST['advanced'] || isset($_POST['save']) )
  144.         $location = "post.php?action=edit&post=$post_ID";
  145.     $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $location);
  146.  
  147.     header("Location: $location"); // Send user on their way while we keep working
  148.  
  149.  
  150.     // Insert categories
  151.     // Check to make sure there is a category, if not just set it to some default
  152.     if (!$post_categories) $post_categories[] = 1;
  153.     foreach ($post_categories as $post_category) {
  154.         // Double check it's not there already
  155.         $exists = $wpdb->get_row("SELECT * FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $post_category");
  156.  
  157.          if (!$exists && $result) { 
  158.             $wpdb->query("
  159.             INSERT INTO $tablepost2cat
  160.             (post_id, category_id)
  161.             VALUES
  162.             ($post_ID, $post_category)
  163.             ");
  164.         }
  165.     }
  166.  
  167.     add_meta($post_ID);
  168.     
  169.     if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
  170.             sleep($sleep_after_edit);
  171.     }
  172.  
  173.     if ($post_status == 'publish') {
  174.         if((get_settings('use_geo_positions')) && ($post_latf != null) && ($post_lonf != null)) {
  175.             pingGeoUrl($post_ID);
  176.         }
  177.  
  178.         if ($post_pingback) {
  179.             pingback($content, $post_ID);
  180.         }
  181.         
  182.         do_action('publish_post', $post_ID);
  183.  
  184.         // Time for trackbacks
  185.         $to_ping = $wpdb->get_var("SELECT to_ping FROM $tableposts WHERE ID = $post_ID");
  186.         $pinged = $wpdb->get_var("SELECT pinged FROM $tableposts WHERE ID = $post_ID");
  187.         $pinged = explode("\n", $pinged);
  188.         if ('' != $to_ping) {
  189.             if (strlen($excerpt) > 0) {
  190.                 $the_excerpt = (strlen(strip_tags($excerpt)) > 255) ? substr(strip_tags($excerpt), 0, 252) . '...' : strip_tags($excerpt)    ;
  191.             } else {
  192.                 $the_excerpt = (strlen(strip_tags($content)) > 255) ? substr(strip_tags($content), 0, 252) . '...' : strip_tags($content);
  193.             }
  194.             $excerpt = stripslashes($the_excerpt);
  195.             $to_pings = explode("\n", $to_ping);
  196.             foreach ($to_pings as $tb_ping) {
  197.                 $tb_ping = trim($tb_ping);
  198.                 if (!in_array($tb_ping, $pinged)) {
  199.                  trackback($tb_ping, stripslashes($post_title), $excerpt, $post_ID);
  200.                 }
  201.             }
  202.         }
  203.  
  204.     } // end if publish
  205.  
  206.     exit();
  207.     break;
  208.  
  209. case 'edit':
  210.     $title = __('Edit');
  211.  
  212.     $standalone = 0;
  213.     require_once('admin-header.php');
  214.  
  215.     $post = $post_ID = $p = (int) $_GET['post'];
  216.     if ($user_level > 0) {
  217.         $postdata = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID = '$post_ID'");
  218.         $authordata = get_userdata($postdata->post_author);
  219.         if ($user_level < $authordata->user_level)
  220.             die ('You don’t have the right to edit <strong>'.$authordata[1].'</strong>’s posts.');
  221.  
  222.         $content = $postdata->post_content;
  223.         $content = format_to_edit($content);
  224.         $edited_lat = $postdata->post_lat;
  225.         $edited_lon = $postdata->post_lon;
  226.         $excerpt = $postdata->post_excerpt;
  227.         $excerpt = format_to_edit($excerpt);
  228.         $edited_post_title = format_to_edit($postdata->post_title);
  229.         $post_status = $postdata->post_status;
  230.         $comment_status = $postdata->comment_status;
  231.         $ping_status = $postdata->ping_status;
  232.         $post_password = $postdata->post_password;
  233.         $to_ping = $postdata->to_ping;
  234.         $pinged = $postdata->pinged;
  235.         $post_name = $postdata->post_name;
  236.  
  237.         include('edit-form-advanced.php');
  238.  
  239.         $post = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID = '$post_ID'");
  240.         ?>
  241. <div id='preview' class='wrap'>
  242.      <h2><?php _e('Post Preview (updated when post is saved)'); ?></h2>
  243.                                                                         <h3 class="storytitle" id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__("Permanent Link: %s"), the_title()); ?>"><?php the_title(); ?></a></h3>
  244.                                                                                                                                                                                                                                                                                     <div class="meta"><?php _e("Filed under:"); ?> <?php the_category(','); ?> — <?php the_author() ?> @ <?php the_time() ?></div>
  245.  
  246. <div class="storycontent">
  247. <?php 
  248. $content = apply_filters('the_content', $post->post_content);
  249. echo $content;
  250. ?>
  251. </div>
  252.         </div>
  253. <?php
  254.     } else {
  255. ?>
  256.         <p><?php printf(__('Since you’re a newcomer, you’ll have to wait for an admin to raise your level to 1, in order to be authorized to post.<br />
  257. You can also <a href="mailto:%s?subject=Promotion?">e-mail the admin</a> to ask for a promotion.<br />
  258. When you’re promoted, just reload this page and you’ll be able to blog. :)'), get_settings('admin_email')); ?>
  259.         </p>
  260. <?php
  261.     }
  262.     break;
  263.  
  264. case 'editpost':
  265. // die(var_dump('<pre>', $_POST));
  266.     $standalone = 1;
  267.     require_once('./admin-header.php');
  268.  
  269.     if ($user_level == 0)
  270.         die (__('Cheatin’ uh?'));
  271.  
  272.     if (!isset($blog_ID)) {
  273.         $blog_ID = 1;
  274.     }
  275.         $post_ID = $_POST['post_ID'];
  276.         $post_categories = $_POST['post_category'];
  277.         if (!$post_categories) $post_categories[] = 1;
  278.         $content = balanceTags($_POST['content']);
  279.         $content = format_to_post($content);
  280.         $excerpt = balanceTags($_POST['excerpt']);
  281.         $excerpt = format_to_post($excerpt);
  282.         $post_title = addslashes($_POST['post_title']);
  283.         if(get_settings('use_geo_positions')) {
  284.             $latf = floatval($_POST["post_latf"]);
  285.                 $lonf = floatval($_POST["post_lonf"]);
  286.                 $latlonaddition = "";
  287.                 if( ($latf != null) && ($latf <= 90 ) && ($latf >= -90) && ($lonf != null) && ($lonf <= 360) && ($lonf >= -360) ) {
  288.                         pingGeoUrl($post_ID);
  289.                 $latlonaddition = " post_lat=".$latf.", post_lon =".$lonf.", ";
  290.                 } else {
  291.                 $latlonaddition = " post_lat=null, post_lon=null, ";
  292.             }
  293.         } else {
  294.             $latlonaddition = '';
  295.         }
  296.         $prev_status = $_POST['prev_status'];
  297.         $post_status = $_POST['post_status'];
  298.         $comment_status = $_POST['comment_status'];
  299.         if (empty($comment_status)) $comment_status = 'closed';
  300.         //if (!$_POST['comment_status']) $comment_status = get_settings('default_comment_status');
  301.  
  302.         $ping_status = $_POST['ping_status'];
  303.         if (empty($ping_status)) $ping_status = 'closed';
  304.         //if (!$_POST['ping_status']) $ping_status = get_settings('default_ping_status');
  305.         $post_password = addslashes($_POST['post_password']);
  306.         $post_name = sanitize_title($_POST['post_name']);
  307.         if (empty($post_name)) $post_name = sanitize_title($post_title);
  308.         $trackback = $_POST['trackback_url'];
  309.     // Format trackbacks
  310.     $trackback = preg_replace('|\s+|', '\n', $trackback);
  311.     
  312.     if (isset($_POST['publish'])) $post_status = 'publish';
  313.  
  314.     if (($user_level > 4) && (!empty($_POST['edit_date']))) {
  315.         $aa = $_POST['aa'];
  316.         $mm = $_POST['mm'];
  317.         $jj = $_POST['jj'];
  318.         $hh = $_POST['hh'];
  319.         $mn = $_POST['mn'];
  320.         $ss = $_POST['ss'];
  321.         $jj = ($jj > 31) ? 31 : $jj;
  322.         $hh = ($hh > 23) ? $hh - 24 : $hh;
  323.         $mn = ($mn > 59) ? $mn - 60 : $mn;
  324.         $ss = ($ss > 59) ? $ss - 60 : $ss;
  325.         $datemodif = ", post_date = '$aa-$mm-$jj $hh:$mn:$ss'";
  326.     $datemodif_gmt = ", post_date_gmt = '".get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss")."'";
  327.     } else {
  328.         $datemodif = '';
  329.         $datemodif_gmt = '';
  330.     }
  331.  
  332.     if ($_POST['save']) {
  333.         $location = $_SERVER['HTTP_REFERER'];
  334.     } elseif ($_POST['updatemeta']) {
  335.         $location = $_SERVER['HTTP_REFERER'] . '&message=2#postcustom';
  336.     } elseif ($_POST['deletemeta']) {
  337.         $location = $_SERVER['HTTP_REFERER'] . '&message=3#postcustom';
  338.     } else {
  339.         $location = 'post.php';
  340.     }
  341.     $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $location);
  342.     header ('Location: ' . $location); // Send user on their way while we keep working
  343.  
  344. $now = current_time('mysql');
  345. $now_gmt = current_time('mysql', 1);
  346.  
  347.     $result = $wpdb->query("
  348.         UPDATE $tableposts SET
  349.             post_content = '$content',
  350.             post_excerpt = '$excerpt',
  351.             post_title = '$post_title'"
  352.             .$datemodif_gmt
  353.             .$datemodif.","
  354.             .$latlonaddition."
  355.             
  356.             post_status = '$post_status',
  357.             comment_status = '$comment_status',
  358.             ping_status = '$ping_status',
  359.             post_password = '$post_password',
  360.             post_name = '$post_name',
  361.             to_ping = '$trackback',
  362.             post_modified = '$now',
  363.             post_modified_gmt = '$now_gmt'
  364.         WHERE ID = $post_ID ");
  365.  
  366.  
  367.     // Now it's category time!
  368.     // First the old categories
  369.     $old_categories = $wpdb->get_col("SELECT category_id FROM $tablepost2cat WHERE post_id = $post_ID");
  370.     
  371.     // Delete any?
  372.     foreach ($old_categories as $old_cat) {
  373.         if (!in_array($old_cat, $post_categories)) // If a category was there before but isn't now
  374.             $wpdb->query("DELETE FROM $tablepost2cat WHERE category_id = $old_cat AND post_id = $post_ID LIMIT 1");
  375.     }
  376.     
  377.     // Add any?
  378.     foreach ($post_categories as $new_cat) {
  379.         if (!in_array($new_cat, $old_categories))
  380.             $wpdb->query("INSERT INTO $tablepost2cat (post_id, category_id) VALUES ($post_ID, $new_cat)");
  381.     }
  382.     
  383.     if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
  384.         sleep($sleep_after_edit);
  385.     }
  386.  
  387.     // are we going from draft/private to published?
  388.     if ($prev_status != 'publish' && $post_status == 'publish') {
  389.         generic_ping();
  390.         if ($post_pingback) {
  391.             pingback($content, $post_ID);
  392.         }
  393.     } // end if moving from draft/private to published
  394.     if ($post_status == 'publish') {
  395.         do_action('publish_post', $post_ID);
  396.         // Trackback time.
  397.         $to_ping = trim($wpdb->get_var("SELECT to_ping FROM $tableposts WHERE ID = $post_ID"));
  398.         $pinged = trim($wpdb->get_var("SELECT pinged FROM $tableposts WHERE ID = $post_ID"));
  399.         $pinged = explode("\n", $pinged);
  400.         if ('' != $to_ping) {
  401.             if (strlen($excerpt) > 0) {
  402.                 $the_excerpt = (strlen(strip_tags($excerpt)) > 255) ? substr(strip_tags($excerpt), 0, 252) . '...' : strip_tags($excerpt)    ;
  403.             } else {
  404.                 $the_excerpt = (strlen(strip_tags($content)) > 255) ? substr(strip_tags($content), 0, 252) . '...' : strip_tags($content);
  405.             }
  406.             $excerpt = stripslashes($the_excerpt);
  407.             $to_pings = explode("\n", $to_ping);
  408.             foreach ($to_pings as $tb_ping) {
  409.                 $tb_ping = trim($tb_ping);
  410.                 if (!in_array($tb_ping, $pinged)) {
  411.                  trackback($tb_ping, stripslashes($post_title), $excerpt, $post_ID);
  412.                 }
  413.             }
  414.         }
  415.     } // end if publish
  416.  
  417.     // Meta Stuff
  418.     if ($_POST['meta']) :
  419.         foreach ($_POST['meta'] as $key => $value) :
  420.             update_meta($key, $value['key'], $value['value']);
  421.         endforeach;
  422.     endif;
  423.  
  424.     if ($_POST['deletemeta']) :
  425.         foreach ($_POST['deletemeta'] as $key => $value) :
  426.             delete_meta($key);
  427.         endforeach;
  428.     endif;
  429.  
  430.     add_meta($post_ID);
  431.  
  432.     do_action('edit_post', $post_ID);
  433.     exit();
  434.     break;
  435.  
  436. case 'delete':
  437.  
  438.     $standalone = 1;
  439.     require_once('./admin-header.php');
  440.  
  441.     check_admin_referer();
  442.  
  443.     if ($user_level == 0)
  444.         die ('Cheatin’ uh?');
  445.  
  446.     $post_id = intval($_GET['post']);
  447.     $postdata = get_postdata($post_id) or die(sprintf(__('Oops, no post with this ID. <a href="%s">Go back</a>!'), 'post.php'));
  448.     $authordata = get_userdata($postdata['Author_ID']);
  449.  
  450.     if ($user_level < $authordata->user_level)
  451.         die (sprintf(__('You don’t have the right to delete <strong>%s</strong>’s posts.'), $authordata[1]));
  452.  
  453.     // send geoURL ping to "erase" from their DB
  454.     $query = "SELECT post_lat from $tableposts WHERE ID=$post_id";
  455.     $rows = $wpdb->query($query); 
  456.     $myrow = $rows[0];
  457.     $latf = $myrow->post_lat;
  458.     if($latf != null ) {
  459.         pingGeoUrl($post);
  460.     }
  461.  
  462.     $result = $wpdb->query("DELETE FROM $tableposts WHERE ID=$post_id");
  463.     if (!$result)
  464.         die(__('Error in deleting...'));
  465.  
  466.     $result = $wpdb->query("DELETE FROM $tablecomments WHERE comment_post_ID=$post_id");
  467.  
  468.     $categories = $wpdb->query("DELETE FROM $tablepost2cat WHERE post_id = $post_id");
  469.  
  470.     if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
  471.         sleep($sleep_after_edit);
  472.     }
  473.  
  474.     $sendback = $_SERVER['HTTP_REFERER'];
  475.     if (strstr($sendback, 'post.php')) $sendback = get_settings('siteurl') .'/wp-admin/post.php';
  476.     header ('Location: ' . $sendback);
  477.     do_action('delete_post', $post_ID);
  478.     break;
  479.  
  480. case 'editcomment':
  481.     $title = __('Edit Comment');
  482.     $standalone = 0;
  483.     $parent_file = 'edit.php';
  484.     require_once ('admin-header.php');
  485.  
  486.     get_currentuserinfo();
  487.  
  488.     if ($user_level == 0) {
  489.         die (__('Cheatin’ uh?'));
  490.     }
  491.  
  492.     $comment = $_GET['comment'];
  493.     $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'javascript:history.go(-1)'));
  494.     $content = $commentdata['comment_content'];
  495.     $content = format_to_edit($content);
  496.  
  497.     include('edit-form-comment.php');
  498.  
  499.     break;
  500.  
  501. case 'confirmdeletecomment':
  502.  
  503. $standalone = 0;
  504. require_once('./admin-header.php');
  505.  
  506. if ($user_level == 0)
  507.     die (__('Cheatin’ uh?'));
  508.  
  509. $comment = $_GET['comment'];
  510. $p = $_GET['p'];
  511. $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  512.  
  513. echo "<div class=\"wrap\">\n";
  514. echo "<p><?php __('<strong>Caution:</strong> You are about to delete the following comment:'); ?></p>\n";
  515. echo "<table border=\"0\">\n";
  516. echo "<tr><td>" . __('Author:') . "</td><td>" . $commentdata["comment_author"] . "</td></tr>\n";
  517. echo "<tr><td>" . __('E-Mail:') . "</td><td>" . $commentdata["comment_author_email"] . "</td></tr>\n";
  518. echo "<tr><td>". __('URL:') . "</td><td>" . $commentdata["comment_author_url"] . "</td></tr>\n";
  519. echo "<tr><td>". __('Comment:') . "</td><td>" . stripslashes($commentdata["comment_content"]) . "</td></tr>\n";
  520. echo "</table>\n";
  521. echo "<p>" . __('Are you sure you want to do that?') . "</p>\n";
  522.  
  523. echo "<form action='".get_settings('siteurl')."/wp-admin/post.php' method='get'>\n";
  524. echo "<input type=\"hidden\" name=\"action\" value=\"deletecomment\" />\n";
  525. echo "<input type=\"hidden\" name=\"p\" value=\"$p\" />\n";
  526. echo "<input type=\"hidden\" name=\"comment\" value=\"$comment\" />\n";
  527. echo "<input type=\"hidden\" name=\"noredir\" value=\"1\" />\n";
  528. echo "<input type=\"submit\" value=\"" . __('Yes') . "\" />";
  529. echo "  ";
  530. echo "<input type=\"button\" value=\"" . __('No') . "\" onClick=\"self.location='". get_settings('siteurl') ."/wp-admin/edit.php?p=$p&c=1#comments';\" />\n";
  531. echo "</form>\n";
  532. echo "</div>\n";
  533.  
  534. break;
  535.  
  536. case 'deletecomment':
  537.  
  538. $standalone = 1;
  539. require_once('./admin-header.php');
  540.  
  541. check_admin_referer();
  542.  
  543. if ($user_level == 0)
  544.     die (__('Cheatin’ uh?'));
  545.  
  546.  
  547. $comment = $_GET['comment'];
  548. $p = $_GET['p'];
  549. if (isset($_GET['noredir'])) {
  550.     $noredir = true;
  551. } else {
  552.     $noredir = false;
  553. }
  554.  
  555. $postdata = get_postdata($p) or die(sprintf(__('Oops, no post with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  556. $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'post.php'));
  557.  
  558. $authordata = get_userdata($postdata['Author_ID']);
  559. if ($user_level < $authordata->user_level)
  560.     die (sprintf(__('You don’t have the right to delete <strong>%1$s</strong>’s post comments. <a href="%2$s">Go back</a>!'), $authordata->user_nickname, 'post.php'));
  561.  
  562. wp_set_comment_status($comment, "delete");
  563. do_action('delete_comment', $comment);
  564.  
  565. if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
  566.     header('Location: ' . $_SERVER['HTTP_REFERER']);
  567. } else {
  568.     header('Location: '. get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
  569. }
  570.  
  571. break;
  572.  
  573. case 'unapprovecomment':
  574.  
  575. $standalone = 1;
  576. require_once('./admin-header.php');
  577.  
  578. check_admin_referer();
  579.  
  580. if ($user_level == 0)
  581.     die (__('Cheatin’ uh?'));
  582.     
  583. $comment = $_GET['comment'];
  584. $p = $_GET['p'];
  585. if (isset($_GET['noredir'])) {
  586.     $noredir = true;
  587. } else {
  588.     $noredir = false;
  589. }
  590.  
  591. $commentdata = get_commentdata($comment) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  592.  
  593. wp_set_comment_status($comment, "hold");
  594.  
  595. if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
  596.     header('Location: ' . $_SERVER['HTTP_REFERER']);
  597. } else {
  598.     header('Location: '. get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
  599. }
  600.  
  601. break;
  602.  
  603. case 'mailapprovecomment':
  604.  
  605. $standalone = 0;
  606. require_once('./admin-header.php');
  607.  
  608. if ($user_level == 0)
  609.     die (__('Cheatin’ uh?'));
  610.  
  611. $comment = $_GET['comment'];
  612. $p = $_GET['p'];
  613. $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  614.  
  615. wp_set_comment_status($comment, "approve");
  616. if (get_settings("comments_notify") == true) {
  617.     wp_notify_postauthor($comment);
  618. }
  619.  
  620. echo "<div class=\"wrap\">\n";
  621. echo "<p>" . __('Comment has been approved.') . "</p>\n";
  622.  
  623. echo "<form action=\"". get_settings('siteurl') ."/wp-admin/edit.php?p=$p&c=1#comments\" method=\"get\">\n";
  624. echo "<input type=\"hidden\" name=\"p\" value=\"$p\" />\n";
  625. echo "<input type=\"hidden\" name=\"c\" value=\"1\" />\n";
  626. echo "<input type=\"submit\" value=\"" . __('Ok') . "\" />";
  627. echo "</form>\n";
  628. echo "</div>\n";
  629.  
  630. break;
  631.  
  632. case 'approvecomment':
  633.  
  634. $standalone = 1;
  635. require_once('./admin-header.php');
  636.  
  637. if ($user_level == 0)
  638.     die (__('Cheatin’ uh?'));
  639.     
  640. $comment = $_GET['comment'];
  641. $p = $_GET['p'];
  642. if (isset($_GET['noredir'])) {
  643.     $noredir = true;
  644. } else {
  645.     $noredir = false;
  646. }
  647. $commentdata = get_commentdata($comment) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  648.  
  649. wp_set_comment_status($comment, "approve");
  650. if (get_settings("comments_notify") == true) {
  651.     wp_notify_postauthor($comment);
  652. }
  653.  
  654.  
  655. if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
  656.     header('Location: ' . $_SERVER['HTTP_REFERER']);
  657. } else {
  658.     header('Location: '. get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
  659. }
  660.  
  661. break;
  662.  
  663. case 'editedcomment':
  664.  
  665.     $standalone = 1;
  666.     require_once('./admin-header.php');
  667.  
  668.     if ($user_level == 0)
  669.         die (__('Cheatin’ uh?'));
  670.  
  671.     $comment_ID = $_POST['comment_ID'];
  672.     $comment_post_ID = $_POST['comment_post_ID'];
  673.     $newcomment_author = $_POST['newcomment_author'];
  674.     $newcomment_author_email = $_POST['newcomment_author_email'];
  675.     $newcomment_author_url = $_POST['newcomment_author_url'];
  676.     $newcomment_author = addslashes($newcomment_author);
  677.     $newcomment_author_email = addslashes($newcomment_author_email);
  678.     $newcomment_author_url = addslashes($newcomment_author_url);
  679.  
  680.     if (($user_level > 4) && (!empty($_POST['edit_date']))) {
  681.         $aa = $_POST['aa'];
  682.         $mm = $_POST['mm'];
  683.         $jj = $_POST['jj'];
  684.         $hh = $_POST['hh'];
  685.         $mn = $_POST['mn'];
  686.         $ss = $_POST['ss'];
  687.         $jj = ($jj > 31) ? 31 : $jj;
  688.         $hh = ($hh > 23) ? $hh - 24 : $hh;
  689.         $mn = ($mn > 59) ? $mn - 60 : $mn;
  690.         $ss = ($ss > 59) ? $ss - 60 : $ss;
  691.         $datemodif = ", comment_date = '$aa-$mm-$jj $hh:$mn:$ss'";
  692.     } else {
  693.         $datemodif = '';
  694.     }
  695.     $content = balanceTags($content);
  696.     $content = format_to_post($content);
  697.  
  698.     $result = $wpdb->query("
  699.         UPDATE $tablecomments SET
  700.             comment_content = '$content',
  701.             comment_author = '$newcomment_author',
  702.             comment_author_email = '$newcomment_author_email',
  703.             comment_author_url = '$newcomment_author_url'".$datemodif."
  704.         WHERE comment_ID = $comment_ID"
  705.         );
  706.  
  707.     $referredby = $_POST['referredby'];
  708.     $referredby = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $referredby);
  709.     if (!empty($referredby)) header('Location: ' . $referredby);
  710.     else header ("Location: edit.php?p=$comment_post_ID&c=1#comments");
  711.     do_action('edit_comment', $comment_ID);
  712.     break;
  713.  
  714. default:
  715.     $standalone = 0;
  716.     $title = __('Create New Post');
  717.     require_once ('./admin-header.php');
  718.  
  719.     if ($user_level > 0) {
  720.         $action = 'post';
  721.         get_currentuserinfo();
  722.         $drafts = $wpdb->get_results("SELECT ID, post_title FROM $tableposts WHERE post_status = 'draft' AND post_author = $user_ID");
  723.         if ($drafts) {
  724.             ?>
  725.             <div class="wrap">
  726.             <p><strong><?php _e('Your Drafts:') ?></strong>
  727.             <?php
  728.             $i = 0;
  729.             foreach ($drafts as $draft) {
  730.                 if (0 != $i)
  731.                     echo ', ';
  732.                 $draft->post_title = stripslashes($draft->post_title);
  733.                 if ($draft->post_title == '')
  734.                     $draft->post_title = sprintf(__('Post # %s'), $draft->ID);
  735.                 echo "<a href='post.php?action=edit&post=$draft->ID' title='" . __('Edit this draft') . "'>$draft->post_title</a>";
  736.                 ++$i;
  737.                 }
  738.             ?>.</p>
  739.             </div>
  740.             <?php
  741.         }
  742.         //set defaults
  743.         $post_status = 'draft';
  744.         $comment_status = get_settings('default_comment_status');
  745.         $ping_status = get_settings('default_ping_status');
  746.         $post_pingback = get_settings('default_pingback_flag');
  747.         $default_post_cat = get_settings('default_post_category');
  748.  
  749.         if (get_settings('advanced_edit')) {
  750.             include('edit-form-advanced.php');
  751.         } else {
  752.             include('edit-form.php');
  753.         }
  754. ?>
  755. <div class="wrap">
  756. <?php _e('<h3>WordPress bookmarklet</h3>
  757. <p>You can drag the following link to your links bar or add it to your bookmarks and when you "Press it" it will open up a popup window with information and a link to the site you’re currently browsing so you can make a quick post about it. Try it out:</p>') ?>
  758. <p>
  759.  
  760. <?php
  761. $bookmarklet_height= (get_settings('use_trackback')) ? 460 : 420;
  762.  
  763. if ($is_NS4 || $is_gecko) {
  764. ?>
  765. <a href="javascript:if(navigator.userAgent.indexOf('Safari') >= 0){Q=getSelection();}else{Q=document.selection?document.selection.createRange().text:document.getSelection();}void(window.open('<?php echo get_settings('siteurl') ?>/wp-admin/bookmarklet.php?text='+escape(Q)+'&popupurl='+escape(location.href)+'&popuptitle='+escape(document.title),'<?php _e('WordPress bookmarklet') ?>','scrollbars=yes,width=600,height=460,left=100,top=150,status=yes'));"><?php printf(__('Press It - %s'), get_settings('blogname')); ?></a> 
  766. <?php
  767. } else if ($is_winIE) {
  768. ?>
  769. <a href="javascript:Q='';if(top.frames.length==0)Q=document.selection.createRange().text;void(btw=window.open('<?php echo get_settings('siteurl') ?>/wp-admin/bookmarklet.php?text='+escape(Q)+'<?php echo $bookmarklet_tbpb ?>&popupurl='+escape(location.href)+'&popuptitle='+escape(document.title),'bookmarklet','scrollbars=yes,width=600,height=<?php echo $bookmarklet_height ?>,left=100,top=150,status=yes'));btw.focus();"><?php printf(__('Press it - %s'), get_settings('blogname')); ?></a> 
  770. <script type="text/javascript" language="JavaScript">
  771. <!--
  772. function oneclickbookmarklet(blah) {
  773. window.open ("profile.php?action=IErightclick", "oneclickbookmarklet", "width=500, height=450, location=0, menubar=0, resizable=0, scrollbars=1, status=1, titlebar=0, toolbar=0, screenX=120, left=120, screenY=120, top=120");
  774. }
  775. // -->
  776. </script>
  777. <br />
  778. <br />
  779. One-click bookmarklet:<br />
  780. <a href="javascript:oneclickbookmarklet(0);">click here</a> 
  781. <?php
  782. } else if ($is_opera) {
  783. ?>
  784. <a href="javascript:void(window.open('<?php echo get_settings('siteurl'); ?>/wp-admin/bookmarklet.php?popupurl='+escape(location.href)+'&popuptitle='+escape(document.title)+'<?php echo $bookmarklet_tbpb ?>','bookmarklet','scrollbars=yes,width=600,height=<?php echo $bookmarklet_height ?>,left=100,top=150,status=yes'));"><?php printf(__('Press it - %s'), get_settings('blogname')); ?></a> 
  785. <?php
  786. } else if ($is_macIE) {
  787. ?>
  788. <a href="javascript:Q='';if(top.frames.length==0);void(btw=window.open('<?php echo get_settings('siteurl'); ?>/wp-admin/bookmarklet.php?text='+escape(document.getSelection())+'&popupurl='+escape(location.href)+'&popuptitle='+escape(document.title)+'<?php echo $bookmarklet_tbpb ?>','bookmarklet','scrollbars=yes,width=600,height=<?php echo $bookmarklet_height ?>,left=100,top=150,status=yes'));btw.focus();"><?php printf(__('Press it - %s'), get_settings('blogname')); ?></a> 
  789. <?php
  790. }
  791. ?>
  792. </p>
  793. </div>
  794. <?php
  795.     } else {
  796.  
  797.  
  798. ?>
  799. <div class="wrap">
  800.       <?php printf(__('<p>Since you’re a newcomer, you’ll have to wait for an admin to raise your level to 1, in order to be authorized to post blog items.<br />
  801. You can also <a href="mailto:%s?subject=Blog posting permission">e-mail the admin</a> to ask for a promotion.<br />
  802. When you’re promoted, just reload this page and you’ll be able to blog. :)</p>'), get_settings('admin_email')); ?>
  803. </div>
  804. <?php
  805.  
  806.     }
  807.  
  808.     break;
  809. } // end switch
  810. /* </Edit> */
  811. include('admin-footer.php');
  812. ?>
  813.